//package com.yj.learn.config;
//
//import com.netflix.client.ClientFactory;
//import com.netflix.client.config.IClientConfig;
//import com.netflix.config.ConfigurationManager;
//import com.netflix.loadbalancer.AvailabilityFilteringRule;
//import com.netflix.loadbalancer.ILoadBalancer;
//import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
//import com.yj.learn.service.TestService;
//import feign.Feign;
//import feign.Logger;
//import feign.Request;
//import feign.Retryer;
//import feign.jackson.JacksonDecoder;
//import feign.jackson.JacksonEncoder;
//import feign.ribbon.LBClient;
//import feign.ribbon.RibbonClient;
//import feign.slf4j.Slf4jLogger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.io.IOException;
//
///**
// * Created by yangbin on 2017/11/16
// */
//@Configuration
//public class FeignConfig {
//
//	private static final Logger logger = new Slf4jLogger();
//
//	private static final org.slf4j.Logger log = LoggerFactory.getLogger(FeignConfig.class);
//
//	private static RibbonClient client = null;
//
//	static {
//		try {
//			ConfigurationManager.loadPropertiesFromResources("ribbon.properties");
//		} catch (IOException e) {
//			log.error("初始化ribbon配置文件失败, 系统启动失败", e);
//			System.exit(0);
//		}
//
//		client = RibbonClient.builder().lbClientFactory(clientName -> {
//			IClientConfig config = ClientFactory.getNamedConfig(clientName);
//			ILoadBalancer lb = ClientFactory.getNamedLoadBalancer(clientName);
//			ZoneAwareLoadBalancer zb = (ZoneAwareLoadBalancer) lb;
//			zb.setRule(new AvailabilityFilteringRule());
//			return LBClient.create(lb, config);
//		}).build();
//	}
//
//	/**	Logger.Level有如下几种选择：
//	 *		NONE, 不记录日志 (默认)。
//	 *		BASIC, 只记录请求方法和URL以及响应状态代码和执行时间。
//	 *		HEADERS, 记录请求和应答的头的基本信息。
//	 *		FULL, 记录请求和响应的头信息，正文和元数据。
//	 */
//	private static Logger.Level logLevel = Logger.Level.FULL;
//
//	@Value("${server_config_interface}")
//	private String configSrvUrl;
//	@Value("${server_zuul_interface}")
//	private String zuulSrvUlr;
//	private static Retryer retryer = new Retryer.Default(5000, 10000, 1);
//	private static Request.Options options = new Request.Options(4*60 * 1000, 4*60  * 1000);
//	private static Request.Options longTimeOptions = new Request.Options(10 * 60 * 1000, 10 * 60 * 1000);
//	private static JacksonDecoder jacksonDecoder = new JacksonDecoder();
//	private static JacksonEncoder jacksonEncoder = new JacksonEncoder();
//
//	@Bean
//	public TestService getSysUserService() {
//		return Feign.builder()
//				.client(client)
//				.encoder(jacksonEncoder)
//				.decoder(jacksonDecoder)
//				.options(options)
//				.retryer(retryer)
//				.logger(logger)
//				.logLevel(logLevel)
//				.target(TestService.class, zuulSrvUlr);
//	}
//}
